import pprint
import time

import requests


def get_zp_stoken(seed, ts):
    # zp = self.get_boos_302()
    data = {
        "group": "boss_rpc",
        "action": "boss",
        "seed": seed,
        "ts": ts
    }
    res = requests.get("http://127.0.0.1:5612/business-demo/invoke", params=data).json()
    # cookie_dict = res["cookie"]
    # print(res["cookie"])
    return res["zp_stoken"]
    # return res["cookie"]


# 快代理
# tunnel = 'e908.kdltps.com:15818'
# username = 't10928946775756'
# password = 'n6zrfqgl'
# proxies = {
#     "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel},
#     "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel}
# }

tunnel = 't445.kdltps.com:15818'
username = 't11100234262638'
password = 'pohgn6h1'
proxies = {
    "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel},
    "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel}
}
sname = '101aba02'
seed = "5UTV0mp+VSWg0tSwcluSlovbUyOcU6i60RvuPF1QTcF+iUhPzRfXdm5+gKFnQ8XHTyd8AhJv869BpeO3xNZ7ug=="
ts = 1709229029409
t = get_zp_stoken(seed, ts)
# c1 = json.loads(c)
# print(type(c1))

# zp_stoken = get_zp_stoken(seed, ts)
# print(zp_stoken)
zp_stoken = 'd4eefNz3Dl8K9ZMK8SCwQBxkNB0YwQD0rLT83MUNCRDc9PUBGNz1FIkAnwrDCt2bDnsOVacOSLzcyPT1FNzdDPUJKIj1JxLzDgD48NlrCvWPDnMOPZsOQXcOHw4IRw7XDgA7DgREuFMOOwr0uLRTCvEI9SEArwr4Uw4nDjsK3E8OEw4fCvRjDgz1AQEI4QQ5eDBpBQEtLVwdSX1JlZVYSU1NUMkBJPEIow7%2FEgjZADg4MDAsMDA4OEQ4ODBkWGRkTExQODgwMCy83wqjDgsKUVsaExIvDv8SbwqHCrcSKwrXEilPDq1jCs8OCwpNawpJ5w73CusKYa8OFYsOJa8OKw4NgYVDCg1hOUsK8wrZjVFlqbFJbaHR8Dw9fZRhoQRjDh8Ktw4c%3D'
headers = {
    'authority': 'www.zhipin.com',
    'referer': 'https://www.zhipin.com',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
    # 'cookie': f'lastCity=101250500; wt2=DWV8PE7jtXpXhpvnJSJI_KDjnFJc8GVE7clg-Jqb7v35zUdF1w-w9NDNZcQRZpSuDN3IAkTLiZCO0sIktpN9j5A~~; wbg=0; zp_at=GZsXm6HyH3zYZshXjasYC-9ZNDFfyQiwbWYCe7LVxJs~; __g=-; __l=l=^%^2Fwww.zhipin.com^%^2Fweb^%^2Fgeek^%^2Fjob^%^3Fquery^%^3DJava^%^26city^%^3D101250100&r=&g=&s=3&friend_source=0; Hm_lvt_194df3105ad7148dcf2b98a91b5e727a=1708930086,1709204996,1709208713; __zp_stoken__={zp_stoken};__zp_sseed__={seed}; __zp_sname__={sname}; __zp_sts__={ts}; __c=1709208712; __a=47128086.1708930085.1709204996.1709208712.152.3.7.152; Hm_lpvt_194df3105ad7148dcf2b98a91b5e727a=1709211430',
    'cookie': f'{zp_stoken}'
}
while 1:
    try:
        url = 'https://www.zhipin.com/wapi/zpgeek/search/joblist.json?scene=1&query=python&city=100010000&page=1&pageSize=30'
        response = requests.get(url, headers=headers, proxies=proxies)
        seed = response.json()['zpData']['seed']
        ts = response.json()['zpData']['ts']
        sname = response.json()['zpData']['name']
        zp_stoken = get_zp_stoken(seed, ts)
        pprint.pprint(response.json())
        print(zp_stoken)
        time.sleep(1)
        break
    except:
        continue
